package com.sgcc.fj.pmos.e_fj_mall.presenter;

import com.sgcc.fj.pmos.common.base.BasePresenter;
import com.sgcc.fj.pmos.common.bean.PowMonth;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.e_fj_mall.bean.OrderCheckResutBean;
import com.sgcc.fj.pmos.e_fj_mall.bean.OrderContentBean;
import com.sgcc.fj.pmos.e_fj_mall.contract.BargainPlaceOrderContract;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Call;

public class BargainPlaceOrderPresenter extends BasePresenter<BargainPlaceOrderContract.View> implements BargainPlaceOrderContract.Presenter {



    @Override
    public void postPlaceOrder(String combId, String startData, String endData, List<PowMonth> mData, String membersSdId, OrderContentBean mContent) {
        Map<String, Object> params = new HashMap<>();
        params.put("combId", combId);
        params.put("startDate", startData);
        params.put("endDate", endData);
        params.put("energyVos", mData);
        params.put("membersSdId", membersSdId);
        params.put("relStatus", "1");
        params.put("isImmediate", "0");
        params.put("mContent", mContent);
        params.put("_t", System.currentTimeMillis());

        HttpRequestUtils.getInstance().request(params, HttpInterConst.PLACE_ORDER_NOW, new MvpNetCallback<OrderCheckResutBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().placeOrderFailed();
            }

            @Override
            public void onResponse(OrderCheckResutBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().placeOrderSuccess(response);
            }
        });
    }
}
